/**
 * Created by 林 on 2017/5/17 0017.
 */
///////////////////////图片轮换//////////////////////////
var aImg = $('.img-action img');
var num = 1;
setInterval(function () {
    if (num == 0) {
        aImg.css({'display': 'none', 'opacity': 0});
        $(aImg[num]).css({'display': 'block'});
        $(aImg[num]).animate({'opacity': 1}, 700);
    } else if (num == 1) {
        aImg.css({'display': 'none', 'opacity': 0});
        $(aImg[num]).css({'display': 'block'});
        $(aImg[num]).animate({'opacity': 1}, 700);
    } else if (num == 2) {
        aImg.css({'display': 'none', 'opacity': 0});
        $(aImg[num]).css({'display': 'block'});
        $(aImg[num]).animate({'opacity': 1}, 700);
    }
    if (num == 2) {
        num = 0;
    } else {
        num++;
    }
}, 4000);
/////////////////////自定义滚动条////////////////////////
//        var contentH = $('.content');
//        var cHeight = $('.content').outerHeight();
//        var scrollH = $('.scroll .scroll-height');
function scroll(num) {
    var contentH = $($('.content')[num]);
    var cHeight = $($('.content')[num]).outerHeight();
    var scrollH = $($('.scroll .scroll-height')[num]);
    var mousewheelevt = (/Firefox/i.test(navigator.userAgent)) ? "DOMMouseScroll" : "mousewheel";//FF doesn't recognize mousewheel as of FF3.x
    if (document.attachEvent){ //if IE (and Opera depending on user setting)
        contentH.get(0).attachEvent("on" + mousewheelevt, function (ev) {
            var ev = ev || event;
            if(ev.wheelDelta < 0 || ev.detail > 0){
                if((580 - scrollH.outerHeight()) - scrollH.position().top > 50 ){
                    scrollH.css('top',scrollH.position().top + 60 +'px');
                    contentH.css('top',(580 - cHeight)*(scrollH.position().top + 60)/(580-scrollH.outerHeight()) + 'px');
                }else {
                    scrollH.css('top',(580 - scrollH.outerHeight()) + 'px');
                    contentH.css('top',(580 - cHeight)*(580 - scrollH.outerHeight())/(580-scrollH.outerHeight()) + 'px');
                }
            }else{
                if( scrollH.position().top > 50 ){
                    scrollH.css('top',scrollH.position().top - 60 +'px');
                    contentH.css('top',(580 - cHeight)*(scrollH.position().top - 60)/(580-scrollH.outerHeight()) + 'px');
                }else {
                    scrollH.css('top','0px');
                    contentH.css('top','0px');
                }
            }
//                    ev.preventDefault();
//                    ev.cancelBubble = true;
        })
    }else if(document.addEventListener) { //WC3 browsers
        contentH.get(0).addEventListener(mousewheelevt, function (ev) {
            var ev = ev || event;
            if(ev.wheelDelta < 0 || ev.detail > 0){
                if((580 - scrollH.outerHeight()) - scrollH.position().top > 50 ){
                    scrollH.css('top',scrollH.position().top + 60 +'px');
                    contentH.css('top',(580 - cHeight)*(scrollH.position().top + 60)/(580-scrollH.outerHeight()) + 'px');
                }else {
                    scrollH.css('top',(580 - scrollH.outerHeight()) + 'px');
                    contentH.css('top',(580 - cHeight)*(580 - scrollH.outerHeight())/(580-scrollH.outerHeight()) + 'px');
                }
            }else{
                if( scrollH.position().top > 50 ){
                    scrollH.css('top',scrollH.position().top - 60 +'px');
                    contentH.css('top',(580 - cHeight)*(scrollH.position().top - 60)/(580-scrollH.outerHeight()) + 'px');
                }else {
                    scrollH.css('top','0px');
                    contentH.css('top','0px');
                }
            }
//                    ev.preventDefault();
//                    ev.cancelBubble = true;
        }, false)
    }
    scrollH.outerHeight(( 580 * 580 ) / cHeight);
}
scroll(0);


/////////////////////////折叠面板///////////////////////////
var panelCollapse5 = $('[data-panel="Collapse1"] .panel');
for (var i = 0; i < panelCollapse5.length; i++) {
    panelCollapse5[i].index = true;
}
panelCollapse5[0].index = false;
panelCollapse5.find('.panel-heading').click(function () {
    if ($(this).parent().get(0).index) {
        panelCollapse5.find('.list-group,.table-responsive,.table,.panel-body').slideUp(300);
        for (var i = 0; i < panelCollapse5.length; i++) {
            panelCollapse5[i].index = true;
        }
        $(this).parent().find('.list-group,.table-responsive,.table,.panel-body').slideDown(300);
        $(this).parent().get(0).index = false;

        setTimeout(function () {
            cHeight = $('.content').outerHeight();

            scrollH = $('.scroll .scroll-height');
            scrollH.outerHeight(( 580 * 580 ) / cHeight);

        },300);

    } else {
        $(this).parent().find('.list-group,.table-responsive,.table,.panel-body').slideUp(300);
        $(this).parent().get(0).index = true;

        setTimeout(function () {
            contentH = $('.content');
            cHeight = $('.content').outerHeight();
            scrollH = $('.scroll .scroll-height');
            scrollH.outerHeight(( 580 * 580 ) / cHeight);
            setTimeout(function () {
                if( panelCollapse5[0].index == true && panelCollapse5[1].index == true && panelCollapse5[2].index == true ){
                    scrollH.css('top',(580 - scrollH.outerHeight()) + 'px');
                    contentH.css('top',(580 - cHeight)*(580 - scrollH.outerHeight())/(580-scrollH.outerHeight()) + 'px');
                }
            },300);

        },300);
    }

});
/////////////////////////右侧点击列表///////////////////////////
var aLi = $('.list li');
var aListContent = $('.content-list');
for(i=0;i<aListContent.length;i++){
    aLi[i].index = i;
}
function ProgressBar(num,wd) {
    var oProgressBar = $('.progress').find('.progress-bar');
    if( $(oProgressBar[num]).hasClass('action') ) {
        $(oProgressBar[num]).css({'width' : wd+'%'});
    }
}
aLi.click(function () {
    for(var i=0;i<aLi.length;i++){
        aLi.removeClass();
    }
    $(this).addClass('active');
    aListContent.css({
        'display':'none',
        '-webkit-transform':'scale(0.2)',
        '-moz-transform':'scale(0.2)',
        '-ms-transform':'scale(0.2)',
        '-o-transform':'scale(0.2)',
        'transform':'scale(0.2)',
        '-webkit-animation':'none',
        '-moz-animation':'none',
        '-o-animation':'none',
        'animation':'none',
        '-webkit-animation-fill-mode': 'none',
        '-moz-animation-fill-mode': 'none',
        '-o-animation-fill-mode': 'none',
        'animation-fill-mode': 'none'
    });
    $(aListContent[this.index]).css({
        'display':'block',
        '-webkit-transform':'scale(0.2)',
        '-moz-transform':'scale(0.2)',
        '-ms-transform':'scale(0.2)',
        '-o-transform':'scale(0.2)',
        'transform':'scale(0.2)',
        '-webkit-animation':'myfirst 1.2s',
        '-moz-animation':'myfirst 1.2s',
        '-o-animation':'myfirst 1.2s',
        'animation':'myfirst 1.2s',
        '-webkit-animation-fill-mode': 'forwards',
        '-moz-animation-fill-mode': 'forwards',
        '-o-animation-fill-mode': 'forwards',
        'animation-fill-mode': 'forwards'
    });

    if(this.index == 0){
        scroll(0);
        $('.progress-bar').removeClass('action').css('width',0);
    }else if(this.index == 1){
        scroll(1);
        $('.progress-bar').addClass('action');
        ProgressBar(0,80);
        ProgressBar(1,85);
        ProgressBar(2,70);
        ProgressBar(3,60);
        ProgressBar(4,70);
        ProgressBar(5,78);
        ProgressBar(6,50);
        ProgressBar(7,60);
        ProgressBar(8,80);
        ProgressBar(9,65);
        ProgressBar(10,75);
        ProgressBar(11,85);
        ProgressBar(12,95);
        ProgressBar(13,50);
        ProgressBar(14,80);
        ProgressBar(15,90);
        ProgressBar(16,80);
        ProgressBar(17,75);
        ProgressBar(18,60);
    }else if(this.index == 2){
        scroll(2);
        $('.progress-bar').removeClass('action').css('width',0);
    }else if(this.index == 3){
        scroll(3);
        $('.progress-bar').removeClass('action').css('width',0);
    }else if(this.index == 4){
        scroll(4);
        $('.progress-bar').removeClass('action').css('width',0);
    }
});
// var xsShow = $('.xs-show');
// for(i=0;i<xsShow.length;i++){
//     xsShow[i].index = i;
// }
// xsShow.click(function () {
//
// });
//////////////////////移动端下的折叠列表////////////////////////
var aListBox = $('.content-list-box');
for(i=0;i<$('.xs-show').length;i++){
    $('.xs-show')[i].index = i;
    $('.xs-show')[i].onOff = true;
}
$('.xs-show').click(function () {
    for(var i=0;i<aListBox.length;i++){
        aListBox.css({'display':'none'});
    }
    $(aListBox[this.index]).css({'display':'block'});
    if(this.index == 1){
        $('.progress-bar').addClass('action');
        ProgressBar(0,80);
        ProgressBar(1,85);
        ProgressBar(2,70);
        ProgressBar(3,60);
        ProgressBar(4,70);
        ProgressBar(5,78);
        ProgressBar(6,50);
        ProgressBar(7,60);
        ProgressBar(8,80);
        ProgressBar(9,65);
        ProgressBar(10,75);
        ProgressBar(11,85);
        ProgressBar(12,95);
        ProgressBar(13,50);
        ProgressBar(14,80);
        ProgressBar(15,90);
        ProgressBar(16,80);
        ProgressBar(17,75);
        ProgressBar(18,60);
    }
});